﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

/*
 * TH07 Groep 10
 * ----------------------------------------------------------------------------------
 * Versie   Door        Commentaar
 * 0.1      Mike/Erwin  Opzet en programmeer werk
 * 0.2      Luca        Naamgeving, C# manier van setters en getters
 * 0.3      Luca        Verplaatst naar Algorithms.Tools, 
 *                      aangepast om als reference te gebruiken
 */

namespace Algorithms.Tools
{
    /// <summary>
    /// Vison Image Class
    /// </summary>
    public class VisionImage
    {
        #region private variables
        private Bitmap bitmap;
        private BitmapData data;
        private int width;
        private int height;
        #endregion

        #region public getters & setters
        public Bitmap Bitmap
        {
            get { return bitmap; }
            set { bitmap = value; }
        }

        public BitmapData Data
        {
            get
            {
                return data;
            }
        }

        public int Height
        {
            get { return height; }
        }

        public int Width
        {
            get { return width; }
        }
        #endregion

        #region constructors
        public VisionImage(Bitmap source, bool newBitmap = false)
        {
            if (newBitmap)
            {

                source = new Bitmap(source);
            }
            else
            {
                this.bitmap = source;
            }
            width = source.Width;
            height = source.Height;
        }

        public VisionImage(int width, int height)
        {
            bitmap = new Bitmap(width, height);
            this.width = width;
            this.height = height;
        }
        #endregion

        /// <summary>
        /// Lock the current bitmap
        /// </summary>
        public void Lock()
        {
            data = bitmap.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
        }
        /// <summary>
        /// Unlock the current bitmap, with the bitmapdata
        /// </summary>
        public void Unlock()
        {
            try
            {
                bitmap.UnlockBits(data);
            }
            catch { ;}
        }


      


    }
}
